package com.byapp.fast.common.aspect;

import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
import org.aspectj.lang.reflect.MethodSignature;
import org.springframework.stereotype.Component;

import java.lang.reflect.Method;

@Component
@Aspect
@Slf4j
public class LogAspect {

    @Pointcut("@annotation(com.byapp.fast.common.annotation.ByLog)")
    public void logPointCut() {
    }

    @Around("logPointCut()")
    public Object around(ProceedingJoinPoint joinPoint) throws Throwable {
        MethodSignature signature = (MethodSignature) joinPoint.getSignature();

        Method method = signature.getMethod();
        // 获取类名
        String className = joinPoint.getTarget().getClass().getName();

        // 获取方法名
        String methodName = method.getName();

        // 获取请求参数
        Object[] args = joinPoint.getArgs();


        // 执行目标方法
        Object result = joinPoint.proceed();
        return result;
    }


}
